#!/usr/bin/perl 
# ids.pl
use warnings;
use strict;

# get user names and primary groups
my (%users, %usergroup);
while (my ($name, $passwd, $uid, $gid) = getpwent) {
	$users{$name} = $uid;
	$usergroup{$name} = $gid;
}

# get group names and gids
my (%groups, @groups);
while (my ($name, $passwd, $gid) = getgrent) {
	$groups{$name} = $gid;
	$groups[$gid] = $name;
}

# print out basic user and group information
foreach my $user (sort {$users{$a} <=> $users{$b}} keys %users) {
	print "$users{$user}: $user, group $usergroup{$user} ($groups[$usergroup{$user}])\n";
}